package com.salelogistics.sale.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.salelogistics.common.log.annotation.Log;
import com.salelogistics.common.log.enums.BusinessType;
import com.salelogistics.common.security.annotation.RequiresPermissions;
import com.salelogistics.sale.domain.SmsDeliveryPlanDetails;
import com.salelogistics.sale.service.ISmsDeliveryPlanDetailsService;
import com.salelogistics.common.core.web.controller.BaseController;
import com.salelogistics.common.core.web.domain.AjaxResult;
import com.salelogistics.common.core.utils.poi.ExcelUtil;
import com.salelogistics.common.core.web.page.TableDataInfo;

/**
 * 月配送计划详细货物Controller
 *
 * @author Hu Kangying
 * @date 2023-07-13
 */
@RestController
@RequestMapping("/deliveryDetails")
public class SmsDeliveryPlanDetailsController extends BaseController {

    @Autowired
    private ISmsDeliveryPlanDetailsService smsDeliveryPlanDetailsService;

    /**
     * 查询月配送计划详细货物列表
     */
    @RequiresPermissions("sale:deliveryDetails:list")
    @GetMapping("/list")
    public TableDataInfo list(SmsDeliveryPlanDetails smsDeliveryPlanDetails) {
        startPage();
        List<SmsDeliveryPlanDetails> list = smsDeliveryPlanDetailsService.selectSmsDeliveryPlanDetailsList(smsDeliveryPlanDetails);
        return getDataTable(list);
    }

    /**
     * 导出月配送计划详细货物列表
     */
    @RequiresPermissions("sale:deliveryDetails:export")
    @Log(title = "月配送计划详细货物", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SmsDeliveryPlanDetails smsDeliveryPlanDetails) {
        List<SmsDeliveryPlanDetails> list = smsDeliveryPlanDetailsService.selectSmsDeliveryPlanDetailsList(smsDeliveryPlanDetails);
        ExcelUtil<SmsDeliveryPlanDetails> util = new ExcelUtil<SmsDeliveryPlanDetails>(SmsDeliveryPlanDetails.class);
        util.exportExcel(response, list, "月配送计划详细货物数据");
    }

    /**
     * 获取月配送计划详细货物详细信息
     */
    @RequiresPermissions("sale:deliveryDetails:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(smsDeliveryPlanDetailsService.selectSmsDeliveryPlanDetailsById(id));
    }

    /**
     * 新增月配送计划详细货物
     */
    @RequiresPermissions("sale:deliveryDetails:add")
    @Log(title = "月配送计划详细货物", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SmsDeliveryPlanDetails smsDeliveryPlanDetails) {
        return toAjax(smsDeliveryPlanDetailsService.insertSmsDeliveryPlanDetails(smsDeliveryPlanDetails));
    }

    /**
     * 修改月配送计划详细货物
     */
    @RequiresPermissions("sale:deliveryDetails:edit")
    @Log(title = "月配送计划详细货物", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SmsDeliveryPlanDetails smsDeliveryPlanDetails) {
        return toAjax(smsDeliveryPlanDetailsService.updateSmsDeliveryPlanDetails(smsDeliveryPlanDetails));
    }

    /**
     * 删除月配送计划详细货物
     */
    @RequiresPermissions("sale:deliveryDetails:remove")
    @Log(title = "月配送计划详细货物", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(smsDeliveryPlanDetailsService.deleteSmsDeliveryPlanDetailsByIds(ids));
    }
}
